<!--
Meeting room reservation list
会议室预约列表
 ? '/pages/personal/history?tabIndex=2'
: `/subscribe/roompay?page_type=1&meetingDate=${current[index].day}&meetingRoomId=${item.id}&time=${current[index].timeStr}`
-->
<template>
  <view class="metting-room">
    <PageWarpper page-name="共享会议室选择">
      <template v-slot:main>
        <view class="reservation-groups border-top">
			<view class="reservation-group border-bottom" v-for="(item, index) in meetingList" :key="index">
				<view class="reservation-group-item" :class="subIndex == 1?'border-left':''" v-for="(subItem, subIndex) in item" :key="subItem.meetingName" @click="openPage(`/subscribe/roompay?page_type=1&meetingRoomId=${subItem.id}`)">
					<label for="" class="siyuan-medium">{{ subItem.meetingName }}</label>
					<label for="" class="siyuan-medium"><text class="intel-one-mono-medium">BAC</text> <text class="intel-one-mono-medium ml">1</text>幢</label>
				</view>
			</view>
			
			<view class="look border-top border-bottom f13 siyuan-medium" @click="queryOrder()">查看预约码</view>
        </view>  
      </template>
    </PageWarpper>
  </view>
</template>

<script setup>
import { useStore } from "vuex";
import { onMounted, ref } from "vue";
import PageWarpper from "@/components/Layer/PageWarpper.vue";
import { getMeetingList ,getHistoryOrderList } from "@/server/api.js";
import { getWeek,isLogin ,openPage} from "@/util/index.js";

const store = useStore();

let meetingList = ref([]); // 会议室的列表
let current = ref([]);
let orderList = ref([]); // 会议室的订单

onMounted(() => {
  getMeetingList({
    userId: 0,
  }).then(res => {
    let list = res.data.meetingRoomVOS || [];
	const newList = [];
	
	for (let i = 0; i < list.length; i += 2) {
	  newList.push(list.slice(i, i + 2));
	}
	
	console.log('获取列表的数据',newList)
	meetingList.value = [...newList];
  });
  getHistoryOrderList({
	  current: 1, 
	  productType: 3, 
	  size: 100
  }).then(res=>{
	  // 获取会议室的订单
	  let successList = [];
	  res.data.records.map(item=>{
		  if(item.orderStatus == 1){
			  successList.push(item)
		  }
	  })
	  orderList.value = [...successList];
  })
});

function getTime(time) {
  return time ? time.split("-")[1] + "/" + time.split("-")[2] : "";
}

function queryOrder(){
	if(isLogin(true)) {
		switch(orderList.value.length){
			case 0:
				uni.showToast({
					icon: 'none',
					title: "暂无订单",
				})
			break;
			case 1: 
				openPage(`/subscribe/roompay?page_type=${orderList.value[0].orderStatus == 1 ? 2 : 1}&id=${orderList.value[0].id}&orderNo=${
            orderList.value[0].orderNo
          }`)
			break;
			default: 
				openPage('/subscribe/meetingroomlist')
			break;
		}
	}
}


function toggleClick(day, index, time, str, subIndex) {
  current.value[index].day = day;
  current.value[index].subIndex = subIndex;
  current.value[index].time = time;
  if (str) current.value[index].timeStr = str;
}
</script>

<style lang="scss" scoped>
.reservation-groups {
  .reservation-group {
	  white-space: nowrap;
	  background-color: #FFFFFF;
	  .reservation-group-item {
		  width: 50%;
		  padding: 106rpx 0 92rpx;
		  display: inline-block;
		  text-align: center;
		  label {
			display: block;
			.intel-one-mono-medium.ml{
				margin-left: 18rpx;
			}
		  }
		  label + label {
			  margin-bottom: 12rpx;
		  }
	  }
  }
  .look {
	  margin-top: 136rpx;
	  padding: 40rpx 0;
	  text-align: center;
	  background-color: #FFFFFF;
  }
}


</style>
